abstract class Activity {
    String activityId
    String name
    String description
    Area area
    Integer mode=1  //define in which mode this project is visible: 0=budget only; 1=sandbox only; 2=both; default:sandbox only;
    
    static hasMany = [amountOfHour : Whoa]
    
    static belongsTo = Area
    
    static constraints = {
        activityId(size:1..20, unique:true, blank:false)
        name(size:1..200, blank:false, unique:true)
        description(size:0..4096)
    }

   // abstract public void addEmployee(Employee e);

    /* delete all employees linked to this activity */
    public void delAllEmployees(){
        List<Employee> l = this.getListOfEmployees()
        for(Employee e : l){
            this.delEmployee(e,2)
        }
    }

    /* delete all employees linked to this activity */
    public void delAllEmployeesMode(Integer currentMode){
        List<Employee> l = this.getListOfEmployeesByMode(currentMode)
        for(Employee e : l){
            this.delEmployee(e,currentMode)
        }
    }

    /* Delete an employee from activity */
    public void delEmployee(Employee e, int delMode){
        for(Whoa a in amountOfHour ){
            if((a?.member.id == e.id && a?.mode == delMode) || delMode==2){
                //if in sandboxMode
                if(delMode==1){
                    // make the entry visible only in budget mode (set mode to 0)
                    if(a?.mode==1){
                        this.removeFromAmountOfHour(a);
                        a.delete();
                        return;
                    }

                }
                else{ //if in budget mode
                    //delete entry from database
                    this.removeFromAmountOfHour(a);
                    a.delete();
                    return;
                }
            }
        }
        //this.removeFromMembers(e);
    }
   public List<Employee> getListOfEmployees(){
        ArrayList<Employee> l = new ArrayList<Employee>();
        for(Whoa a in amountOfHour){
            l.add(a?.member);
        }
        return l;
   }

    public List<Employee> getListOfEmployeesByMode(Integer wantedMode){ // mode 0 for budget or 1 for sandbox
        ArrayList<Employee> l = new ArrayList<Employee>();
        for(Whoa a in amountOfHour){
            if(wantedMode==a?.mode || a?.mode == 2){
                l.add(a?.member);
            }
        }
        return l;
   }

    public int getMode(Employee emp){
        int mode=1;
        for(Whoa a in amountOfHour){
            if(a?.member.id==emp.id) return a?.mode;
        }
        return mode;
    }

   abstract public Float calcTotalCost();
   abstract public Float calcTotalIncome();

    public String toString(){
        return name+" ("+activityId+")";
    }

}
